from random import uniform
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse


def index(request):
    ctx = {}
    return render(request, "visualdata/data.html", ctx)


def getdata(request):
    if request.method == "GET":
        data = [
            {"time": "2022-01-01 00:01:00", "temperature": uniform(37.0, 37.5)},
            {"time": "2022-01-01 00:02:00", "temperature": uniform(37.0, 37.5)},
            {"time": "2022-01-01 00:03:00", "temperature": uniform(37.0, 37.5)},
            {"time": "2022-01-01 00:04:00", "temperature": uniform(37.0, 37.5)},
            {"time": "2022-01-01 00:05:00", "temperature": uniform(37.0, 37.5)},
            {"time": "2022-01-01 00:06:00", "temperature": uniform(37.0, 37.5)},
            {"time": "2022-01-01 00:07:00", "temperature": uniform(37.0, 37.5)},
            {"time": "2022-01-01 00:08:00", "temperature": uniform(37.0, 37.5)},
            {"time": "2022-01-01 00:09:00", "temperature": uniform(37.0, 37.5)},
            {"time": "2022-01-01 00:10:00", "temperature": uniform(37.0, 37.5)}
        ]
        return JsonResponse({
            "status_code": 200,
            "data": data,
        })
    else:
        return HttpResponse(status_code=400)
